package com.lh.tams.controller.system;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lh.tams.domain.TamsModule;
import com.lh.tams.domain.TamsRole;
import com.lh.tams.service.system.RoleService;
import com.lh.tams.util.DataGridModel;
import com.lh.tams.util.ID;
import com.lh.tams.util.Page;
import com.lh.tams.util.Status;
import com.lh.tams.util.diy.Json;

/**
 * 角色controller
 * @author liulin
 *
 */
@RequestMapping("/role")
@Controller
public class RoleController {
	
	private RoleService roleService;
	
	public RoleService getRoleService() {
		return roleService;
	}

	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}

	@RequestMapping("/query.adm")
	@ResponseBody
	public Page query(DataGridModel dgm,TamsRole role){
		return roleService.query(dgm, role);
	}
	
	@RequestMapping("/add.adm")
	@ResponseBody
	public Json add(TamsRole role){
		role.setIdBgt(ID.next());
		role.setStatus(Status.STATUS_NORMAL);
		roleService.add(role);
		Json json = new Json();
		return json;
	}
	
	@RequestMapping("/update.adm")
	@ResponseBody
	public Json update(TamsRole role){
		role.setStatus(Status.STATUS_NORMAL);
		roleService.update(role);
		Json json = new Json();
		return json;
	}
	
	@RequestMapping("/del.adm")
	@ResponseBody
	public Json delete(long[] id){
		roleService.delete(id);
		return new Json();
	}
	
	@RequestMapping("/limit.adm")
	@ResponseBody
	public Json limit(long roleId,long[] moduleId){
		roleService.limit(roleId, moduleId);
		return new Json();
	}
	
	@RequestMapping("/queryModule.adm")
	@ResponseBody
	public List<TamsModule> queryModule(long roleId){
		return roleService.queryModule(roleId);
	}
	
}
